package com.wennimei.controllers.renren;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.wennimei.service.MessageTypeService;
import com.wennimei.service.ProcessService;

@Path("")
public class RenRenController {

    private Logger log = Logger.getLogger("RENN");

    @Autowired
    private ProcessService processService;

    @Autowired
    private MessageTypeService messageTypeService;

    @Get
    @Post
    public String index(@Param("c") String content, @Param("uid") String uid) {
        String res = (String) this.processService.getContentResult(
                this.messageTypeService.getMessageType(content, uid), content,
                null, null, uid);
        int count = 1;
        while (res.length() > 240 && count <= 5) {
            res = (String) this.processService.getContentResult(
                    this.messageTypeService.getMessageType(content, uid),
                    content, null, null, uid);
            count++;
        }
        log.info("Q:" + content + ";A:" + res);
        return "@" + res;
    }
}
